//
//  AppDelegate.m
//  HealthA段
//
//  Created by dllo on 15/6/3.
//  Copyright (c) 2015年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"
#import "NewsViewController.h"
#import "HosptialViewController.h"
#import "KnowledgeViewController.h"
#import "FoodViewController.h"
#import "ZWIntroductionViewController.h"
@interface AppDelegate ()
@property (nonatomic, strong) ZWIntroductionViewController *introductionView;
@property(nonatomic, assign)BOOL isFirstStart;
@property(nonatomic, retain)UITabBarController *myTabBar;
@end

@implementation AppDelegate
- (instancetype)init{
    self = [super init];
    if (self) {
        [self isFirstStartProject];
    }
    return self;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    if (self.isFirstStart) {
        NSLog(@"第一次启动");
        NSArray *coverImageNames = @[@"1.jpg", @"4.jpg", @"2.jpg"];
        self.introductionView = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:nil];
        [self.window addSubview:self.introductionView.view];
        __weak AppDelegate *weakSelf = self;
        self.introductionView.didSelectedEnter = ^() {
            [weakSelf.introductionView.view removeFromSuperview];
            weakSelf.introductionView = nil;
            self.myTabBar = [[UITabBarController alloc] init];
            weakSelf.window.rootViewController = self.myTabBar;
            [self creatView];
        };
    }else{
        NSLog(@"不是第一次启动");
        self.myTabBar = [[UITabBarController alloc] init];
        self.window.rootViewController = self.myTabBar;
        [self creatView];
    }
    [_window release];
    return YES;
 }



- (void)creatView{
    NewsViewController *newVC = [[NewsViewController alloc] init];
    UINavigationController *newNA = [[UINavigationController alloc] initWithRootViewController:newVC];
    newNA.navigationBar.translucent = NO;
    newNA.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"健康资讯" image:[UIImage imageNamed:@"zixun"] tag:1001];
    
    HosptialViewController *hosptialVC = [[HosptialViewController alloc] init];
    UINavigationController *hosNA = [[UINavigationController alloc] initWithRootViewController:hosptialVC];
    hosNA.navigationBar.translucent = NO;
    hosptialVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"医疗中心" image:[UIImage imageNamed:@"yiliao"] tag:1002];
    
    KnowledgeViewController *knowVC = [[KnowledgeViewController alloc] init];
    UINavigationController *knowNA = [[UINavigationController alloc] initWithRootViewController:knowVC];
    knowNA.navigationBar.translucent = NO;
    knowVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"健康知识" image:[UIImage imageNamed:@"changshi"] tag:1003];
    
    FoodViewController *foodVC = [[FoodViewController alloc]init];
    UINavigationController *foodNA = [[UINavigationController alloc] initWithRootViewController:foodVC];
    foodNA.navigationBar.translucent = NO;
    foodVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"食品药品" image:[UIImage imageNamed:@"yaopin"] tag:1004];
    
    self.myTabBar.viewControllers = @[newNA,knowNA,hosNA,foodNA];
    self.myTabBar.tabBar.translucent = NO;
 }


- (void)isFirstStartProject
{
    NSFileManager *manager = [NSFileManager defaultManager];
    //获取沙盒路径
    NSArray *sandBox = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *sandBoxPath = [sandBox lastObject];
    //拼接文件路径
    NSString *filePath = [sandBoxPath stringByAppendingPathComponent:@"第一次运行"];
    if (![manager fileExistsAtPath:filePath]) {
        self.isFirstStart = YES;
        //第一次启动之后创建文件
        NSLog(@"%@",filePath);
        [manager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
    }else{
        NSLog(@"%@",filePath);
        self.isFirstStart = NO;
    }
    
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
